package com.yst.shader.feature.ss.effect;


import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

import androidx.annotation.DrawableRes;


public class ImageConfig {
    private Rect mShadowOffset;
    private int mShadowResId;
    private boolean mEnableBackground;
    private boolean mEnableShimmer;

    public ImageConfig(Builder builder) {
        this.mShadowOffset = builder.mOffset;
        this.mShadowResId = builder.mShadow;
        this.mEnableBackground = builder.mEnableBackground;
        this.mEnableShimmer = builder.mEnableShimmer;
    }

    public Rect getOffset() {
        return mShadowOffset;
    }

    public Drawable getShadow(Context context) {
        if (mShadowResId > 0) {
            return context.getResources().getDrawable(mShadowResId);
        }
        return null;
    }

    public boolean isEnableBackground() {
        return mEnableBackground;
    }

    public boolean isEnableShimmer() {
        return mEnableShimmer;
    }

    public static class Builder {
        private Rect mOffset;
        private int mShadow;
        private boolean mEnableBackground;
        private boolean mEnableShimmer;

        public Builder offset(int offset) {
            if (mOffset == null) {
                mOffset = new Rect();
            }
            mOffset.set(offset, offset, offset, offset);
            return this;
        }

        public Builder offset(int left, int top, int right, int bottom) {
            if (mOffset == null) {
                mOffset = new Rect(left, top, right, bottom);
            } else {
                mOffset.set(left, top, right, bottom);
            }
            return this;
        }

        public Builder shadow(@DrawableRes int shadow) {
            this.mShadow = shadow;
            return this;
        }

        public Builder enableBackground(boolean enable) {
            this.mEnableBackground = enable;
            return this;
        }

        public Builder enableShimmer(boolean enable) {
            this.mEnableShimmer = enable;
            return this;
        }

        public ImageConfig build() {
            return new ImageConfig(this);
        }
    }
}
